package com.moli.iov.protocol.model;


import java.io.Serializable;
import java.util.Arrays;

import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.DateTimeTag;
import com.moli.iov.util.ByteArrayUtil;


@Serialize(unit="byte",isBigEndian=true)
public class VehicleRegisterReq extends Header implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6142066114314876771L;
	
	/**
	 * 注册时间
	 */
	@Serialize(unit = "byte", offset = header_offset + 0, size = 6)
	public DateTimeTag registerDate;
	
	@Serialize(unit="byte",offset=header_offset+6,size=2)
	public short serialNum;
	
	/**
	 * vin 需调用ascii转换 ByteArrayUtil.strToAscii()
	 */
	@Serialize(unit="byte",offset=header_offset+8,size=17)
	public String vin;
	
	/**
	 * ICCID 需调用ascii转换 ByteArrayUtil.strToAscii()
	 */
	@Serialize(unit = "byte", offset = header_offset + 25, size = 20)
	public String iccid;
	
	@Serialize(unit = "byte", offset = header_offset + 45, size = 1)
	public short deviceNumLength;
	
	public String deviceNum;

	public DateTimeTag getRegisterDate() {
		return registerDate;
	}

	public void setRegisterDate(DateTimeTag registerDate) {
		this.registerDate = registerDate;
	}

	public short getSerialNum() {
		return serialNum;
	}

	public void setSerialNum(short serialNum) {
		this.serialNum = serialNum;
	}

	public String getVin() {
		return vin;
	}

	public void setVin(String vin) {
		this.vin = vin;
	}

	public String getIccid() {
		return iccid;
	}

	public void setIccid(String iccid) {
		this.iccid = iccid;
	}

	public short getDeviceNumLength() {
		return deviceNumLength;
	}

	public void setDeviceNumLength(short deviceNumLength) {
		this.deviceNumLength = deviceNumLength;
	}

	@Serialize(unit = "byte", offset = header_offset + 45, size = -1)
	public String getDeviceNum() {
		return deviceNum;
	}

	@Serialize(unit = "byte", offset = header_offset + 45, size = -1)
	public void setDeviceNum(byte[] bytes) {
		
		short s = ByteArrayUtil.toShort(bytes[0]);
		if(s>0){
			byte[] deviceNumbytes = Arrays.copyOfRange(bytes,1,s+1);
			deviceNum = ByteArrayUtil.asciiToStr(deviceNumbytes);
		}
	}

	@Override
	public String toString() {
		return "VehicleRegisterReq [registerDate=" + registerDate
				+ ", serialNum=" + serialNum + ", vin=" + vin + ", iccid="
				+ iccid + ", deviceNumLength=" + deviceNumLength
				+ ", deviceNum=" + deviceNum + "]";
	}
	
	

}
